<template>
  <div class="tab-bar-item" @click="clickItem">
    <div v-if="!isActive">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="item-icon-active"></slot>
    </div>
    <div :style="{ color: isActiveColor }">
      <slot name="item-text"></slot>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    path: {
      type: String,
      default: "/home",
      require: true,
    },
    activeColor: "",
  },
  data() {
    return {
      //   isActive: true,
    };
  },
  computed: {
    isActive() {
      return this.$route.path === this.path;
      //   return this.$route.path.indexOf(this.path) != -1;
    },
    isActiveColor() {
      return this.isActive ? this.activeColor : "";
    },
  },
  methods: {
    clickItem() {
      this.$router.push({ path: this.path });
    },
  },
};
</script>
<style lang="scss" scoped>
.tab-bar-item {
  flex: 1;
  text-align: center;
  img {
    width: 24px;
  }
  //   div.active {
  //     color: red;
  //   }
}
</style>
